package com.goktech.sportsmall.service.Impl;

import com.goktech.sportsmall.bean.AddressBean;
import com.goktech.sportsmall.mapper.AddressMapper;
import com.goktech.sportsmall.service.AddressService;
import com.goktech.sportsmall.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class AddressServiceImpl implements AddressService {

    @Autowired(required = false)
    private AddressMapper addressMapper;

    // 添加信息
    @Override
    public Map<String,Object> insertAddress(AddressBean addressBean) {
        addressBean.setA_create_time(DateUtil.getDate("yyyy/MM/dd HH:mm:ss"));
        int address = addressMapper.insertAddress(addressBean);
        Map<String,Object> haspMap = new HashMap<>();
        haspMap.put("title","添加地址信息");
        if (address == 1) {
            haspMap.put("message","添加成功");
            haspMap.put("data",addressBean);
            haspMap.put("time",DateUtil.getDate("yyyy/MM/dd HH:mm:ss"));
        }
        return haspMap;
    }

    // 查询信息
    @Override
    public Map<String,Object> selectAddress() {
        Map<String,Object> haspMap = new HashMap<>();
        haspMap.put("title","查询地址信息");
        haspMap.put("data",addressMapper.selectAddress());
        haspMap.put("time", DateUtil.getDate("yyyy/MM/dd HH:mm:ss"));
        return haspMap;
    }

    // 删除信息
    @Override
    public Map<String,Object> deleteAddress(int a_id) {
        int address = addressMapper.deleteAddress(a_id);
        Map<String,Object> haspMap = new HashMap<>();
        Map<String,Object> has = new HashMap<>();
        haspMap.put("title","删除地址信息");
        if (address == 1) {
            haspMap.put("message","删除成功");
            has.put("a_id",a_id);
            haspMap.put("data",has);
            haspMap.put("time",DateUtil.getDate("yyyy/MM/dd HH:mm:ss"));
        }
        return haspMap;
    }

    @Override
    public Map<String, Object> updateAddress(AddressBean addressBean) {
        int address = addressMapper.updateAddress(addressBean);
        Map<String,Object> haspMap = new HashMap<>();
        haspMap.put("title","修改地址信息");
        if (address == 1) {
            haspMap.put("message","修改成功");
            haspMap.put("data",addressBean);
            haspMap.put("time",DateUtil.getDate("yyyy/MM/dd HH:mm:ss"));
        }
        return haspMap;
    }

}
